<?php
include("./Core/Common.php");
$url=daddslashes($_GET['url']);
$authcode=daddslashes($_GET['authcode']);

define("VERSION",$conf['vers']);//最新版本号
$content=$conf['content'];//未授权显示内容
$allowupdate=$conf['is_up'];
$uplog=$conf['uplog'];

if(!$_GET['ver'] && ($url=='localhost' || $url=='127.0.0.1'))exit();

if($_GET['ver']) {

	$param=base64_encode(authcode($_GET['ver']."\t".$url."\t".$authcode."\t".(time()+604800),'ENCODE',$conf['KEY']));
	$download=$siteurl.'Download.php?update=true&param='.$param.'&rand='.rand(100000,999999);

	if($allowupdate=='开启更新') {
		if($_GET['ver']>=$conf['ver']) {
			$code=0;
			$msg='<font color="green">您使用的已是最新版本！</font><br/>当前版本：'.$conf['ver'].' (Build '.VERSION.')';
		} else {
			$code=1;
			$msg='<font color="red">发现新版本(～￣▽￣)～！</font> 最新版本：'.$conf['ver'].' (Build '.VERSION.')';
		}
	} else {
		$code=0;
		$msg='<font color="blue">更新服务器正在维护，请稍后访问！</font>';
	}
}

$row=$DB->query("SELECT * FROM `pay_check` WHERE `url`='{$url}' limit 1")->fetch();
if($row and $row['authcode']!=$authcode){
	$result=array('code'=>'-1','msg'=>'授权码不正确,请下载更新包覆盖更新!');
}elseif($row and $row['status']==0 and $row['beizhu']!=''){
	$result=array('code'=>'-1','msg'=>$row['beizhu']);
}elseif(checkauth($url,$authcode)) {
	if($_GET['ver'])
		$result=array('code'=>$code,'msg'=>$msg,'uplog'=>str_replace(array("\r\n", "\n", "\r"), "<br>", str_replace(" ", " ", $uplog)),'file'=>$download);
	else
		$result=array('code'=>'1','authcode'=>$authcode);
}else{
	
	$result=array('code'=>'-1','msg'=>$content);
}
echo json_encode($result);

?>